<template>
	<view class="container" style="	background-color: aqua;">
		<view class="top" @touchmove.stop.prevent="moveHandle">
			<uni-data-picker v-model="page.classify" :localdata="noteClassifyList" placeholder="请选择分类" popup-title="分类" :map="{
					text: 'dictLabel',
					value: 'dictCode'
				}"  @change="noteClassifyChange">
			</uni-data-picker>
		</view>
		<view style="height: 68upx;">
			<!-- 为了占位置 -->

		</view>
		<note-card v-for="(note,index) of noteList" :note="note"></note-card>
	</view>
</template>

<script>
	import NoteCard from '@/components/noteList/NoteCard.vue'
	import {
		Base64
	} from 'js-base64';

	export default {
		components: {
			NoteCard
		},
		data() {
			return {
				noteList: [],
				noteClassifyList: [],
				page: {
					pageNum: 1,
					pageSize: 20,
					title: "",
					classify:""
				},
			}

		},
		onLoad: function(option) {
			this.page.title = option.key
		},
		created() {
			//加载记录字典类型
			this.$api.getSystemDictDataList({
				dictType: "zone_note_classify",
				pageSize: 999999
			}).then(res => {
				console.info(res)
				this.noteClassifyList = res.rows
			})
			this.getNoteList("one");

		},
		methods: {
			noteClassifyChange(e) {
				console.info(e)
				//写入txt
				this.getNoteList("one")
			},
			moveHandle() {
				return true
			},
			getNoteList(e) {
				if ("one" === e) {
					this.page.pageNum = 1
					this.noteList = []
				}
				if ("next" === e) {
					this.page.pageNum = this.page.pageNum + 1
				}
				console.log(this.page)
				let res = this.$api.getNoteList(this.page).then(res => {
					res.rows.forEach(row => {
						if (row.content) {
							row.content = this.$common.dealRichTextImg(Base64.decode(row.content))
							row.content = this.$common.dealRichTextTagP(row.content)
							// console.info("处理过后的富文本---》" + row.content)
						}
						this.noteList.push(row)
					})
				});
			},
			clickLoadMore(e) {
				console.info("加载更多")
			}

		},
		onReachBottom() {
			console.info("加载更多2")
			this.getNoteList("next");
		},
		onPullDownRefresh() {
			console.info("加载更多23")
			this.getNoteList("one");
			uni.stopPullDownRefresh()
		},
	}
</script>

<style>
	.top {
		/* 固定在顶部 */
		position: fixed;
		/* 层级 */
		z-index: 999;
		background-color: aqua;
		width: 750upx;
	}
</style>